import requests
from lxml import etree

url = 'https://www.ximalaya.com/yinyue/54070700/'
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
}
response = requests.get(url, headers=header)
print(response.status_code)

# print(response.text)
ehtml = etree.HTML(response.text)
musicnames = ehtml.xpath('//div[@class="text Mi_"]/a/@title')
print(musicnames)
musiclinks = ehtml.xpath('//div[@class="text Mi_"]/a/@href')
print(musiclinks)

for i,j in zip(musiclinks,musicnames):
    id = i.split('/')[-1]
    murl = 'https://www.ximalaya.com/revision/play/v1/audio?id='+id+'&ptype=1'
    res = requests.get(murl,headers=header)
    newaddr = res.json()['data']['src']
    mres = requests.get(newaddr)
    data = mres.content
    filename = j.split('/')[-1]+'.mp3'
    with open(filename,'wb') as f:
        f.write(data)